let app =getApp();
Page({
  data: {
    category:app.data.category,
    ProductList:app.data.productList,
    activeKey:0,
    cateList:20,
    scrollTop:0,
    refresh:false,
    loading:false,
    intoTop:'cate0'
  },
  //options(Object)
  onLoad: function(options) {
    app.cache_add(this);
  },
  onReady: function() {
    
  },
  onShow: function() {
    
  },
  onHide: function() {

  },
  onUnload: function() {
    app.cache_off(this);
  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  },
  onPageScroll: function() {

  },
  //item(index,pagePath,text)
  onTabItemTap:function(item) {

  },
  lower(){
    if(this.data.activeKey<(this.data.cateList-1)){
      this.setData({
        // intoTop:'cate'+(parseInt(this.data.activeKey)+1),
        // activeKey:this.data.activeKey+1,
        // scrollTop:0
      })
    }
  },
  onaddCart(e){
    console.info(e);
    let goods = e.detail.goods;
    let index = e.detail.index;
    this.selectComponent("#suk").getProductsDetail(goods.id,index);
  },
  onChange(e){
    console.info(e);
    this.setData({
      intoTop:'cate'+e.detail,
      activeKey:e.detail,
      scrollTop:0,
      loading:true
    },()=>{
      setTimeout(()=>{
        this.setData({
          loading:false
        })
      },1000)
    })
  },
  getTopView(){
    this.setData({
      scrollTop:0
    })
  },
  scroll(e){
    console.info(e);
    if (e.detail.scrollTop > 200) {
      this.selectComponent("#totop").open();
    } else {
      this.selectComponent("#totop").close();
    }
    // 超出停止视频
    const videoId = app.videoId;
    if(videoId){
      let query = wx.createSelectorQuery();
      let wh = wx.getSystemInfoSync().windowHeight;
      query.select('#productItem' + videoId).boundingClientRect(rect => {
            if (rect.top < -rect.height || rect.bottom > (rect.height+wh)) {
              app.videoId = null;
              app.videoContext[videoId].pause();
            }
      }).exec();
    }
  },
  // 下拉刷新
  refresherrefresh(){
    console.info("下拉刷新");
    let that=this;
    setTimeout(()=>{
      that.setData({
        refresh:false
      })
    },2000)
  }
});
  